package com.sgcc.csc.util;

import com.sgcc.csc.framework.jdbc.page.PageResult;

/**
 * Copyright (C), 2008-2020, 国家电网公司客户服务中心信息运维中心
 * Project:  wxws
 *
 * @author: bingdor
 * Date:     2020/7/27 9:10 上午
 * Description: //模块目的、功能描述
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
public class JsonResult<T> {
    /**
     * 成功
     */
    public static final int SUCCESS = 0;
    /**
     * 失败
     */
    public static final int FAILURE = 1;
    private static final String SUCCESS_MSG = "success";
    /**
     * 重定向
     */
    public static final int REDIRECT = 302;
    private int code;
    private String msg;
    private T data;
    private int nums;
    private PageResult pageResult;

    public static <T> JsonResult<T> newInstance(){
        return new JsonResult<>();
    }
    
    public static <T> JsonResult<T> newInstance(int code){
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setCode(code);
        return jsonResult;
    }

    public static <T> JsonResult<T> successResult() {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setCode(SUCCESS);
        jsonResult.setMsg(SUCCESS_MSG);
        return jsonResult;
    }

    public static <T> JsonResult<T> successResult(T data) {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setCode(SUCCESS);
        jsonResult.setMsg(SUCCESS_MSG);
        jsonResult.setData(data);
        return jsonResult;
    }
    public static <T> JsonResult<T> errorResult(String msg) {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setCode(FAILURE);
        jsonResult.setMsg(msg);
        return jsonResult;
    }

    public int getNums() {
        return nums;
    }

    public void setNums(int nums) {
        this.nums = nums;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public PageResult getPageResult() {
        return pageResult;
    }

    public void setPageResult(PageResult pageResult) {
        this.pageResult = pageResult;
    }
}
